﻿using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Huioo.Learning.Serilog.ConsoleApp2
{
    internal class CustomPolicy : IDestructuringPolicy
    {
        public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory,
            [NotNullWhen(true)] out LogEventPropertyValue? result)
        {
            if (value is not MyDto dto)
            {
                result = null;
                return false;
            }

            result = new StructureValue(new List<LogEventProperty>
            {
                new LogEventProperty("Identifier", new ScalarValue(dto.Id)),
                new LogEventProperty("NormalizedName", new ScalarValue(dto.Name.ToUpperInvariant()))
            });

            return true;
        }
    }

    public record MyDto(int Id, string Name);
}
